Primer Jupyter Notebook¶

Coses que podem fer¶

Podem escriure text descriptiu. Així podem donar tot tipus d'explicacions perquè el lector sàpiga què estem fent.

També podem incloure codi, com veurem a continuació.

Comencem amb alguns exemples.

Python senzill¶

In [1]:
def print_hi(name):
    print(f'Hi, {name}')
if __name__ == '__main__':
    print_hi('PyCharm')
Hi, PyCharm

Un altre exemple:

In [2]:
cars = ['Volvo', 'Seat', 'VW', 'Mercedes']
print (cars[1])
Seat

I ara fem un dibuix

In [3]:
import pandas as pd
import plotly.express as px

# Create pandas DataFrame from a CSV and concatenate a second DataFrame
df = pd.read_csv('C:/Users/Pep/Documents/Figura2.csv')
df1 = pd.read_csv('C:/Users/Pep/Documents/Figura3.csv')
df = pd.concat([df, df1], ignore_index=True)

# Make legend discrete
df['Series'] = df['Series'].astype(str)

print(df)

# Plot the data
fig = px.scatter(df, x='Date', y='Antimony', color='Series',
                 title='Test scatter plot',
                 labels=dict(Date='Year of publication',
                             Antimony='Antimony / ng L<sup>-1</sup>', Series='Series number')
                 )
fig.update_traces(marker=dict(size=12,
                              line=dict(width=0)),
                  selector=dict(mode='markers'))
fig.update_yaxes(range=[0, 1000],
                 minor_ticks="inside", tickcolor='black',
                 ticks="inside", ticklen=8, minor_ticklen=5,
                 showline=True, linewidth=1, linecolor='black', mirror=True,
                 showgrid=True, gridwidth=1, gridcolor='grey')
fig.update_xaxes(showline=True, linewidth=1, linecolor='black', mirror=True,
                 showgrid=True, gridwidth=1, gridcolor='grey',
                 minor_ticks="inside", minor_ticklen=5, minor_dtick=1)  # nticks=15

# Create plot
fig.show()
     Date  Antimony Series
0    1965     260.0      1
1    1965     460.0      1
2    1965     240.0      1
3    1965     210.0      1
4    1965     250.0      1
..    ...       ...    ...
123  2013     368.0      4
124  2013     525.0      4
125  2013     259.0      4
126  2016     164.0      4
127  2020     438.0      4

[128 rows x 3 columns]